package tron.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
@Aspect
public class TronAop {

    @Pointcut("execution(* tron.controller.*.*(..))")
    public void pointcutOne() {

    }

    @Around(value = "pointcutOne()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("方法执行前：");
        Object[] args = proceedingJoinPoint.getArgs();
        String name = proceedingJoinPoint.getSignature().getName();
        System.out.println("获取方法参数：" + Arrays.toString(args) + " 方法名：" + name);
        Object result = null;
        try {
            result = proceedingJoinPoint.proceed();
        } catch (Throwable throwable) {
            throw  throwable;
        }finally {
            System.out.println("方法执行后：");
            System.out.println("获取方法的返回结果：" + result);
        }
        return result;
    }
}
